package cn.iocoder.yudao.module.crossborder.platform.dal.mysql.platformapiconfig;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.crossborder.platform.dal.dataobject.platformapiconfig.PlatformApiConfigDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.crossborder.platform.controller.admin.platformapiconfig.vo.*;

/**
 * 跨境电商平台API配置 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface PlatformApiConfigMapper extends BaseMapperX<PlatformApiConfigDO> {

    default PageResult<PlatformApiConfigDO> selectPage(PlatformApiConfigPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PlatformApiConfigDO>()
                .eqIfPresent(PlatformApiConfigDO::getPlatformId, reqVO.getPlatformId())
                .eqIfPresent(PlatformApiConfigDO::getStoreId, reqVO.getStoreId())
                .eqIfPresent(PlatformApiConfigDO::getApiType, reqVO.getApiType())
                .likeIfPresent(PlatformApiConfigDO::getApiName, reqVO.getApiName())
                .eqIfPresent(PlatformApiConfigDO::getApiEndpoint, reqVO.getApiEndpoint())
                .eqIfPresent(PlatformApiConfigDO::getHttpMethod, reqVO.getHttpMethod())
                .eqIfPresent(PlatformApiConfigDO::getRequestHeaders, reqVO.getRequestHeaders())
                .eqIfPresent(PlatformApiConfigDO::getRequestParams, reqVO.getRequestParams())
                .eqIfPresent(PlatformApiConfigDO::getResponseMapping, reqVO.getResponseMapping())
                .eqIfPresent(PlatformApiConfigDO::getRateLimitPerMinute, reqVO.getRateLimitPerMinute())
                .eqIfPresent(PlatformApiConfigDO::getRateLimitPerHour, reqVO.getRateLimitPerHour())
                .eqIfPresent(PlatformApiConfigDO::getRateLimitPerDay, reqVO.getRateLimitPerDay())
                .eqIfPresent(PlatformApiConfigDO::getTimeoutSeconds, reqVO.getTimeoutSeconds())
                .eqIfPresent(PlatformApiConfigDO::getRetryTimes, reqVO.getRetryTimes())
                .eqIfPresent(PlatformApiConfigDO::getRetryIntervalSeconds, reqVO.getRetryIntervalSeconds())
                .eqIfPresent(PlatformApiConfigDO::getStatus, reqVO.getStatus())
                .eqIfPresent(PlatformApiConfigDO::getEnabled, reqVO.getEnabled())
                .eqIfPresent(PlatformApiConfigDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(PlatformApiConfigDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(PlatformApiConfigDO::getId));
    }

    /**
     * 根据平台ID查询API配置列表
     *
     * @param platformId 平台ID
     * @return API配置列表
     */
    default List<PlatformApiConfigDO> selectListByPlatformId(Long platformId) {
        return selectList(new LambdaQueryWrapperX<PlatformApiConfigDO>()
                .eq(PlatformApiConfigDO::getPlatformId, platformId)
                .orderByAsc(PlatformApiConfigDO::getApiType));
    }

}